package com.wanhe.base;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import com.wanhe.base.injector.component.BaseApplicationComponent;
import com.wanhe.base.injector.component.DaggerBaseApplicationComponent;
import com.wanhe.base.injector.module.BaseApplicationModule;
import com.wanhe.base.util.FileDownLoadUtil;

import java.io.File;

import javax.inject.Inject;

/**
 * Created by cdj on 2017/6/26.
 */

public class BaseApplication extends Application {

    private static BaseApplicationComponent mApplicationComponent;

	public static Context context;

    @Override
	public void onCreate() {
		super.onCreate();
		initInject();
		context =this;
		initFileSystemCache();
		FileDownLoadUtil.initFileDownloader();
	}

	public static BaseApplicationComponent getApplicationComponent(){
        return mApplicationComponent;
    }

	/**
	 *
	 * 应用基础注入
	 *
	 * @author 陈德基
	 * @time 2017/6/26 10:59
	 */
	private void initInject() {
		mApplicationComponent = DaggerBaseApplicationComponent.builder()
				.baseApplicationModule(new BaseApplicationModule(this)).build();
	}


	private void initFileSystemCache() {
		Log.d("MainApplication","initFile");
		generateFileCache(Const.fileBaseUrl);
		generateFileCache(Const.imageBaseUrl);
		generateFileCache(Const.gifBaseUrl);
		generateFileCache(Const.videoBaseUrl);
		generateFileCache(Const.cacheBaseUrl);
		generateFileCache(Const.IMG_CACHE);
	}
	private void generateFileCache(String url){
		File file = new File(url);
		if (!file.exists()){
			Log.d("initFile","url="+url);
			file.mkdirs();
		}
	}
}
